PICKLISTS ----------------------------------------------------------- There are three steps to creating a picklist. 1. Create the pick list pointer. 2. Add items to the pick list. 3. Attach the pick list to a frame. optionmptr createpicklist(fontptr fonttype); Creates the initial picklist pointer. Note that a picklist is built up from the same list as a menu. void definepickitem(optionmptr om, char *entrystr, callproc entrycallproc, char *pickitem); Adds an item to the pick list. The OM is the picklist previously created with a call to createpicklist. entrystr is the next item to be added to the pick list. entrycallproc is an event-handler to call when the item is `picked'. Note that you must define a this event-handler EVEN IF IT DOES NOTHING. Do not use nilunitproc here. pickitem is a string where a copy of the entrystr is put. Generally all the entries for a given pick list would use the pickitem. void definepicklistarea(imagestkptr fs, unsigned x, unsigned y, unsigned oeselect, unsigned displaynum, optionmptr om); Attaches and displays a pick list on a frame. The fs is the frame the picklist is being attached to. x,y are the coordinates of the upper left corner of the pick list. These are relative to the frame. oeselect is the item to show as selected on entry to the picklist. If oeselect is greater that the number of entries in the picklist then no item is selected. displaynum is the number of items to display on the picklist. displaynum must be greater than 0. 1 is a special instance for the picklist, when used the picklist is converted to a Drop-Down pick list. That is, only the selected entry is shown with a button to the right. When the button is pressed the pick list is dropped-down. If displaynum is less that the total number of picklist items then a scroll bar is displayed on the picklist, both regular and drop-down picklists. Here is a simple program that displays a pick list. BEGINFILE> pick1.c /* pick1.c */ #include "teglsys.h" char ispicked[40]; unsigned waspicked( imagestkptr ifs, msclickptr ms) { return 1; } void createpickframe(void) { optionmptr pom; imagestkptr ifs; unsigned x1 = 100; unsigned y1 = 100; unsigned x2 = 100; unsigned y2 = 100; quickframe(&ifs,&x1,&y1,&x2,&y2); pom = createpicklist(f8x8bold); setpicklistmargin(pom,12); definepickitem(pom,"Item 1",waspicked,ispicked); definepickitem(pom,"Item 2",waspicked,ispicked); definepickitem(pom,"Item 3",waspicked,ispicked); definepicklistarea(ifs,10,10,2,5,pom); } void main(void) { easytegl(); easyout(); createpickframe(); teglsupervisor(); } ENDFILE> Of course a real program would do something with the result of the pick. It's easy to tie in the pick event to another event that will look after the result. BEGINFILE> pick2.c /* -- Pick2.c */ #include "teglsys.h" char ispicked[40]; unsigned waspicked( imagestkptr ifs, msclickptr ms) { imagestkptr locfs; dropstackimage(ifs); pushimage(100,100,200,200); prepareforupdate(stackptr); shadowbox(100,100,200,200); setcolor(BLACK); outtextxy(110,110,ispicked); commitupdate(); return 0; } void createpickframe(void) { optionmptr pom; imagestkptr ifs; unsigned x1 = 100; unsigned y1 = 100; unsigned x2 = 100; unsigned y2 = 100; quickframe(&ifs,&x1, &y1, &x2, &y2); pom = createpicklist(f8x8bold); setpicklistmargin(pom,12); definepickitem(pom,"Item 1",waspicked,ispicked); definepickitem(pom,"Item 2",waspicked,ispicked); definepickitem(pom,"Item 3",waspicked,ispicked); definepicklistarea(ifs,10,10,2,5,pom); } void main(void) { easytegl(); easyout(); createpickframe(); teglsupervisor(); } ENDFILE> Here is a fairly complete and useful example of a picklist reading the directory and displaying it. It also shows how to handle it when a file is double clicked on. A more comprehensive routine would sort the filenames before sending them to the picklist and some mechanism would enable the user to move through directories. BEGINFILE> pick3.c /* -- pick3.c */ #include "teglsys.h" #ifdef QUICKC #include #include #else #include "dir.h" #endif char ispicked[40]; /* -- stores the picked file name */ /* -- drops the picklist when the frame is disposed of */ unsigned droppicklist(imagestkptr fs,unsigned userkey,void *dataarea) { optionmptr picklist = (optionmptr) dataarea; dropoptionmenu(picklist); return 0; } /* -- simple, but handy */ void setviewporttoframe(imagestkptr ifs) { setviewport(ifs->x,ifs->y,ifs->x1,ifs->y1,TRUE); } /* -- this event is called whenever a an item is clicked on */ unsigned waspicked(imagestkptr ifs, msclickptr ms) { setviewporttoframe(ifs); /* -- set relative to frame */ setfillstyle(SOLID_FILL, WHITE); /* -- usual colors */ bar(10,10,140,20); /* -- bar out old file name */ setcolor(BLACK); /* -- black letters */ outtextxy(10,10,ispicked); /* -- show selection */ /* -- left double click just checks to see if the left mouse button */ /* -- was pressed again (within the double click delay) after entering */ /* -- this function. If so then it means the file was selected and we */ /* -- should exit. */ if (leftdoubleclick()) dropstackimage(ifs); return 0; } /* -- just tidy up the files name to make it more acceptable in the pick */ /* -- list view. */ char * fmtfilename(char * s) { static char s1[21]; strcpy(s1,s); while (strlen(s1) < 12) strcat(s1," "); return s1; } /* -- findfirst etc. are in your TURBO manual */ void getfilename(char * path, char * filearg, unsigned attr) { #ifdef QUICKC struct find_t dd; #else struct ffblk dd; /* -- store directory entries */ #endif optionmptr pom; imagestkptr ifs; char fullpath[80]; int done; unsigned x1 = 100; unsigned y1 = 100; unsigned x2 = 200; unsigned y2 = 200; quickframe(&ifs,&x1,&y1,&x2,&y2); setproportional(FALSE); pom = createpicklist(f8x8bold); setuserdataarea(stackptr,5432,pom,droppicklist); setviewporttoframe(ifs); setteglfont(f8x8bold); setcolor(BLACK); rectangle(5,5,150,23); outtextxy(10,10,filearg); outtextxy(10,35,path); strcpy(fullpath,path); strcat(fullpath,filearg); #ifdef QUICKC done = _dos_findfirst(fullpath, _A_SUBDIR, &dd); #else done = findfirst(fullpath,&dd,attr); #endif while (!done) { #ifdef QUICKC definepickitem(pom,fmtfilename(dd.name),waspicked,ispicked); #else definepickitem(pom,fmtfilename(dd.ff_name),waspicked,ispicked); #endif done = findnext(&dd); } /* -- attach it */ definepicklistarea(ifs,10,60,0,12,pom); } char *current_directory(char *path) { strcpy(path, "X:\\"); /* fill string with form of response: X:\ */ #ifdef QUICKC getcwd(path,80); #else path[0] = 'A' + getdisk(); /* replace X with current drive letter */ getcurdir(0, path+3); /* fill rest of string with current directory */ #endif return(path); } char curdir[80]; void main(void) { easytegl(); easyout(); /* -- for example just load the names */ current_directory(curdir); getfilename(curdir,"\\*.*",FA_ARCH); /* -- of all the files in the current */ /* -- directory. */ teglsupervisor(); } ENDFILE> void clearpicklist(optionmptr om); Resets a pick list. All the entries are disposed of but the picklist is not. After clearpicklist is the same as having just created a picklist using createpicklist. void setpicklistwidth(optionmptr om, unsigned maxwidth); Set the maximum width of the picklist. om is a pickllist previously created with createpicklist. maxwidth is the maximim width of the picklist in pixels. void setpicklistmargin(optionmptr om, unsigned marginw); Sets the margin around the text of the picklist. om is a picklist previously created with createpicklist. marginw is the margin, in pixels, on the left and right side of the text. --------- Picklists can be disposed of with a call to DropOptionMenu since they use the same data structure and list mechanism as option menus. void dropoptionmenu(optionmptr om); ---- END picklist.txt